package com.bootdo.common.config;


import java.io.File;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.bootdo.common.utils.ToolUtil;

@Component
@ConfigurationProperties(prefix="bootdo")
public class BootdoConfig {
	//上传路径
	private String uploadPath;

	public String getUploadPath() {
		return uploadPath;
	}
	 private Boolean haveCreatePath = false;
	public void setUploadPath(String uploadPath) {
		this.uploadPath = uploadPath;
	}
	  private String fileUploadPath;
	  
	   public String getFileUploadPath() {
	        //如果没有写文件上传路径,保存到临时目录
	        if (ToolUtil.isEmpty(fileUploadPath)) {
	            return getTempPath();
	        } else {
	            //判断有没有结尾符,没有得加上
	            if (!fileUploadPath.endsWith(File.separator)) {
	                fileUploadPath = fileUploadPath + File.separator;
	            }
	            //判断目录存不存在,不存在得加上
	            if (haveCreatePath == false) {
	                File file = new File(fileUploadPath);
	                file.mkdirs();
	                haveCreatePath = true;
	            }
	            return fileUploadPath;
	        }
	    }
	   
	   /**
	     * 获取临时目录
	     */
	    public static String getTempPath(){
	        return System.getProperty("java.io.tmpdir");
	    }
}
